#pragma once
#include <fstream>
#include "EngineObject.h"

namespace DreamEngine
{
class _EngineExport CFileDataStream : public CEngineObject
{

public:
	enum AccessMode
	{
		READ	= std::ios::in, 
		WRITE	= std::ios::out,
		APP	    = std::ios::app,
		TRUNC   = std::ios::trunc,

		READ_BINARY	= std::ios::in|std::ios::binary, 
		WRITE_TRUNC = std::ios::out|std::ios::trunc,
		WRITE_APP	= std::ios::out|std::ios::app,
	};

	enum FilePos
	{
		END		=	std::ios::end, 
		CUR		=	std::ios::cur,
		BEGIN	=	std::ios::beg,
	};

public:
	CFileDataStream(void);
	~CFileDataStream(void);

	template <class T>
	CFileDataStream& operator << (const T& vaule)
	{
		if (IsOpen())
			m_fstream << vaule;

		return *this;
	}

	bool		Open(const std::string& fileName, AccessMode mode=READ);
	bool		Close(void);
	bool		IsOpen(void)const;

	bool		Read(void* pBuffer, int dateSize);
	void		Write(const void* pBuffer, int dateSize);

	void		MoveToBegin(void);
	void		MoveToEnd(void);

	int			GetOffset(int relatPos=0);
	bool		IsEnd(void);

	void        GetAsString(std::string& str);
	std::string     GetAsString(void);

protected:

	int				m_size;
	std::string		m_fileName;
	std::fstream	m_fstream;
};
}
